{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fewer-techno",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mclass\u001b[39m \u001b[36mUser\u001b[39m\r\n",
       "\u001b[36muserBase\u001b[39m: \u001b[32mList\u001b[39m[\u001b[32mUser\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mUser\u001b[39m(\u001b[32m\"T\"\u001b[39m, \u001b[32m28\u001b[39m),\n",
       "  \u001b[33mUser\u001b[39m(\u001b[32m\"K\"\u001b[39m, \u001b[32m33\u001b[39m),\n",
       "  \u001b[33mUser\u001b[39m(\u001b[32m\"J\"\u001b[39m, \u001b[32m44\u001b[39m),\n",
       "  \u001b[33mUser\u001b[39m(\u001b[32m\"D\"\u001b[39m, \u001b[32m23\u001b[39m)\n",
       ")\r\n",
       "\u001b[36mts\u001b[39m: \u001b[32mList\u001b[39m[\u001b[32mString\u001b[39m] = \u001b[33mList\u001b[39m(\u001b[32m\"T\"\u001b[39m, \u001b[32m\"D\"\u001b[39m)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "case class User(name: String,age: Int)\n",
    "val userBase = List(User(\"T\",28),User(\"K\",33),User(\"J\",44),User(\"D\",23))\n",
    "val ts = for(user <- userBase if (user.age >= 20 && user.age < 30)) yield user.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dressed-monitor",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "T\n",
      "D\n"
     ]
    }
   ],
   "source": [
    "ts foreach(name => println(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "incredible-nothing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mxx\u001b[39m"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def xx(n:Int,v:Int) = for(i <- 0 until n ;j <- i until n if i+j == v) yield (i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "focused-integral",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1,9)\n",
      "(2,8)\n",
      "(3,7)\n",
      "(4,6)\n",
      "(5,5)\n"
     ]
    }
   ],
   "source": [
    "xx(10,10) foreach{\n",
    "    case (i,j) => println(s\"($i,$j)\")\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "given-scoop",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
